#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

class SuggestHandler(webapp.RequestHandler):
  def makeSuggest(self, params):
    suggest = {}
    suggest['query'] = params['query']
    suggest['count'] = 3
    suggest['hints'] = []
    for hint in [u' борщ', u' суп', u' салат']:
      suggest['hints'].append(params['query'].encode('utf-8') + hint.encode('utf-8'))
    return json.dumps(suggest)
    
  def get(self):
    params = self.parseParams()
    self.response.headers['Content-Type'] = 'application/json'
    response = params['callback'] + '(' + self.makeSuggest(params) + ');'
    self.response.out.write(response)

  def parseParams(self):
    """Filter the param set to the expected params."""
    params = {
      'query': '',
      'count': '10',
      'callback': ''
    }
    for k, v in params.iteritems():
      # Possibly replace default values.
      params[k] = self.request.get(k, v)
    return params
